<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>One day escape</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <link rel="stylesheet" href="src/css/n.min.css">
    <link rel="stylesheet" href="src/css/datepicker.css">
    <script>
        (function(){
            var phoneWidth =  parseInt(window.screen.width);
            var phoneScale = phoneWidth/640;
            var isAndroid = RegExp("Android").test(navigator.userAgent);
            if (isAndroid) {
                document.write('<meta name="viewport" content="width=640, minimum-scale = '+phoneScale+', maximum-scale = '+phoneScale+', target-densitydpi=device-dpi">');
            } else {
                document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
            }
        }());
    </script>
</head>

<body class="app" style="width: 100%;height: 100%;">

    <div class="container light-gray" style="width: 640px;margin: 0 auto;">

        <div id="rendez-vous"></div>

        <div id="J_jalendar" class="jalendar"></div>

    </div>

    <script src="src/js/jquery.js"></script>
    <script src="src/js/handlebars.js"></script>
    <script src="src/js/rendezvous.js"></script>
    <script src="src/js/datepicker.js"></script>

    <script>

        $(document).ready(function($){

            function userDate(uData){
                var myDate = new Date(uData*1000);
                var year = myDate.getFullYear();
                var month = myDate.getMonth() + 1;
                var day = myDate.getDate();
                return year + '-' + month + '-' + day;
            }

            var getParam = function(name){
                var search = document.location.search;
                var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
                var matcher = pattern.exec(search);
                var items = null;
                if(null != matcher){
                    try{
                        items = decodeURIComponent(decodeURIComponent(matcher[1]));
                    }catch(e){
                        try{
                            items = decodeURIComponent(matcher[1]);
                        }catch(e){
                            items = matcher[1];
                        }
                    }
                }
                return items;
            };


            function renderList() {

                var groupId = getParam('group_id');

                $.ajax({
                    data: {
                        parameters: '{common:{},data:{group_id:"' + groupId + '"}}'
                    },
                    type: "GET",
                    dataType: 'jsonp',
                    jsonp: 'jsoncallback',
                    url: 'http://www.one-dao.com/api/group/oneDayEscape/getArrange?callback=?',
                    success: function(json){
                        var arrangeList = [];
                        var eventHTML = '';
                        if(json.code === 1) {
                            arrangeList = json.data.arrange_list;
                            if(arrangeList.length) {
                                $.each(arrangeList, function(index, item) {
                                    var date =  userDate(item.date);
                                    var group_id = item.group_id;
                                    console.log(date, group_id);
                                    eventHTML += '<div class="added-event" data-date="' + date + '" data-title="' + group_id + '"></div>';
                                });

                                $('#J_jalendar').html(eventHTML);

                                $('#J_jalendar').jalendar({
                                    color: '#fff',
                                    type: 'linker',
                                    dateType: 'yyyy-mm-dd',
                                    titleColor: '#999',
                                    weekColor: '#999',
                                    todayColor: '#FFF',
                                    callback: function() {
                                        $('.have-event').click(function(e) {
                                            e.preventDefault();
                                            var groupId = $(this).find('.event-single').text();
                                            window.location.href = 'http://www.one-dao.com/html/yidaozou/yapp/groupinfo.html?gid=' + groupId + '&toBack=' + encodeURIComponent(location.href);
                                        });
                                    }
                                });

                            }
                        }
                    },
                    error: function(xhr) {}
                })

            }

//            $('#rendez-vous').RendezVous({
//                canClose: false,
//                openByDefault: true,
//                i18n: {
//                    calendar: {
//                        month: {
//                            previous: '上一月',
//                            next:     '下一月',
//                            up:       '选择月份'
//                        },
//                        year: {
//                            previous: '上一年',
//                            next:     '下一年',
//                            up:       '选择年份'
//                        },
//                        decade: {
//                            previous: '上十年',
//                            next:     '下十年',
//                            up:       '选择日期'
//                        }
//                    },
//                    days: {
//                        abbreviation: {
//                            monday:    '一',
//                            tuesday:   '二',
//                            wednesday: '三',
//                            thursday:  '四',
//                            friday:    '五',
//                            saturday:  '六',
//                            sunday:    '日'
//                        },
//                        entire: {
//                            monday:    '星期一',
//                            tuesday:   '星期二',
//                            wednesday: '星期三',
//                            thursday:  '星期四',
//                            friday:    '星期五',
//                            saturday:  '星期六',
//                            sunday:    '星期日'
//                        }
//                    },
//                    months: {
//                        abbreviation:
//                        {
//                            january:   '一月',
//                            february:  '二月',
//                            march:     '三月',
//                            april:     '四月',
//                            may:       '五月',
//                            june:      '六月',
//                            july:      '七月',
//                            august:    '八月',
//                            september: '九月',
//                            october:   '十月',
//                            november:  '十一月',
//                            december:  '十二月'
//                        },
//                        entire: {
//                            january:   '一月',
//                            february:  '二月',
//                            march:     '三月',
//                            april:     '四月',
//                            may:       '五月',
//                            june:      '六月',
//                            july:      '七月',
//                            august:    '八月',
//                            september: '九月',
//                            october:   '十月',
//                            november:  '十一月',
//                            december:  '十二月'
//                        }
//                    }
//                }
//            }, function(rdv) {
//                console.log(rdv);
//                renderList();
//            });

            renderList();
        });
    </script>

</body>

</html>
